package acwing._1_1AlgorithmBasic._4Math;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._4Math
 * @File : Q0875.java
 * @Author : WangRuoyu
 * @Date : 2023/4/5 9:00
 */

import java.io.*;

public class Q0877 {

    static int exgcd(int a, int b, int[] x, int[] y) {
        if (b == 0) {
            x[0] = 1;
            y[0] = 0;
            return a;
        }
        int d = exgcd(b, a % b, y, x);
        y[0] -= a / b * x[0];
        return d;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);

        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            int[] x = new int[1];
            int[] y = new int[1];
            exgcd(a, b, x, y);
            wr.write(x[0] + " " + y[0] + "\n");
        }
        wr.flush();
    }
}